package session1.practises;

import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Scanner;

public class ArrayTest {
	public static void main(String[] args) {
		LinkedList<Integer> buf=new LinkedList<>();
		LinkedList[] subArrays;
		ArrayThread[] arrayThreads;
		Scanner scanner=new Scanner(System.in);
		System.out.println("请输入数组元素（输入字符退出）");
		while (true){
			try {buf.add(scanner.nextInt());}
			catch (InputMismatchException e)
			{scanner.nextLine();break;}
		}
		System.out.printf("您输入了%3d个数字；您想要拆分成几个子数组？\n",buf.size());
		subArrays=new LinkedList[scanner.nextInt()];
		for(int i=0;i<subArrays.length;i++)
			subArrays[i]=new LinkedList<>();
		for(int i=0;!buf.isEmpty();i++)
			subArrays[i%subArrays.length].add(buf.removeFirst());
		for(int i=0;i<subArrays.length;i++)
			System.out.println(Arrays.toString(subArrays[i].toArray()));

//		Collections.sort(buf);
//		System.out.println(Arrays.toString(buf.toArray()));
	}
}
class ArrayThread extends Thread{
	public ArrayThread(LinkedList<Integer> linkedList) {
		this.array=new int[linkedList.size()];
		for (int i=0;i<array.length;i++)
			this.array[i]=linkedList.removeFirst();
	}
	public int[] getArray() {
		Arrays.sort(this.array);
		return array;
	}
	int[] array;
}